﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Globalization;

namespace SilverAnts.Utilities
{
    /// <summary>
    /// 系统信息
    /// </summary>
    public static class HardwareInfo
    {
        /** 
         * WQL查询语句
        // 网卡原生MAC地址
        "SELECT * FROM Win32_NetworkAdapter WHERE (MACAddress IS NOT NULL) AND (NOT (PNPDeviceID LIKE 'ROOT%'))",
         L"PNPDeviceID",
        // 硬盘序列号
        "SELECT * FROM Win32_DiskDrive WHERE (SerialNumber IS NOT NULL) AND (MediaType LIKE 'Fixed hard disk%')",
        L"SerialNumber",
        // 主板序列号
        "SELECT * FROM Win32_BaseBoard WHERE (SerialNumber IS NOT NULL)",
        L"SerialNumber", 
        // 处理器ID
        "SELECT * FROM Win32_Processor WHERE (ProcessorId IS NOT NULL)",
        L"ProcessorId",
        // BIOS序列号
        "SELECT * FROM Win32_BIOS WHERE (SerialNumber IS NOT NULL)",
        L"SerialNumber",
        // 主板型号
        "SELECT * FROM Win32_BaseBoard WHERE (Product IS NOT NULL)",
        L"Product",
        // 网卡当前MAC地址
        "SELECT * FROM Win32_NetworkAdapter WHERE (MACAddress IS NOT NULL) AND (NOT (PNPDeviceID LIKE 'ROOT%'))",
        L"MACAddress",
        * */
        public static string[] Serials;
        static HardwareInfo()
        {
            Serials = new string[4];
            //-BIOS
            ManagementObjectSearcher bios = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
            foreach (ManagementObject mo in bios.Get())
            {
                Serials[0] = mo["SerialNumber"].ToString().Trim();
            }
            //-CPU序列号
            ManagementObjectSearcher cpu = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
            foreach (ManagementObject mo in cpu.Get())
            {
                Serials[1] = mo["ProcessorId"].ToString().Trim();
            }
            //-硬盘序列号
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
            foreach (ManagementObject mo in searcher.Get())
            {
                Serials[2] = mo["SerialNumber"].ToString().Trim();
                break;
            }
            //-网卡地址
            ManagementObjectSearcher mac = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))");
            foreach (ManagementObject mo in searcher.Get())
            {
                Serials[3] = mo["MACAddress"].ToString().Trim();
            }
        }
    }
}
